#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;
class Solution
{
    /**
     * 给定一个无重复元素的数组 candidates 和一个目标数 target ，
     * 找出 candidates 中所有可以使数字和为 target 的组合。
     * candidates 中的数字可以无限制重复被选取。
     */
public:
    vector<vector<int>> ans;
    vector<int> slice;
    void dfs(vector<int> &candidates, int cur, int sum, int target)
    {
        if (sum == target)
        {
            ans.push_back(slice);
        }
        if (sum > target)
            return;
        for (int i = cur; i < candidates.size(); ++i)
        {
            slice.push_back(candidates[i]);
            dfs(candidates, i, sum + candidates[i], target);
            slice.pop_back();
        }
    }
    vector<vector<int>> combinationSum(vector<int> &candidates, int target)
    {
        dfs(candidates, 0, 0, target);
        return ans;
    }
};